<?php
/**
 * ShiftStatus function
 *
 * Return the status of shifts for an employee.
 *
 * @author Will Zhao <kexinzhao666@gmail.com>
 */
include_once 'SCconn.php';
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';
/**
 * @param $userName string
 * @param $userPassHash string
 * @param $empID string
 * @return array|null
 */
function shiftStatus($userName, $userPassHash,$empID)
{
    $err=new ErrorCode();
	//$hash_from_db = db_get_hash('millions');
	//$us='Chen';
	$emid="";
	if(checkAuthentication($userName,$userPassHash))
	{
		$conn=mysql_open();
		mysql_select_db("paradigmshift_dev", $conn);
		 $count  =  count($empID); 
		if($count>0)
		{
		    $emid=" where";
			for($i=0;$i<$count;$i++)
			{
			   if($i<$count-1)
			   {
		       		$emid=$emid." empID=".$empID[$i]." or";
			   }
			   else
			   {
			        $emid=$emid." empID=".$empID[$i];
			   } 		
			}
		}
		$result=mysql_query("select roles.roleName,dates.datestamp,
roledate.startTime,roledate.endTime,
roledate.shiftStatus
from  paradigmshift_dev.roledate left join (roles,dates)
on roles.roleID=roledate.roleID and dates.dateID=roledate.dateID".$emid,$conn);
		/*echo "<table id='users' class='ui-widget ui-widget-content'>
		 <thead>
		<tr class='ui-widget-header '>
		<th>roleID</th>
		<th>empID</th>
		<th>dateID</th>
		<th>StartDate</th>
		<th>EndDate</th>
		<th>shiftStatus</th>
		<th>date</th>
		</tr>
		</thead>";*/
		$count=mysql_num_rows($result);
		if ($count<=0)
	    {
		     return null;
		     $error =$err->failRead;
		}
		while($row=mysql_fetch_array($result))
		{
		$array[] = array(
				'roleName'=>$row['roleName'],
				'date'=>$row['datestamp'],
				'startTime'=>$row['startTime'],
				'startTime'=>$row['endTime'],
				'shiftStatus'=>$row['shiftStatus']);
		}
		mysql_close($conn);
		//return $result;
		return $array;
		$error=$err->successRead;
	}
	else
	{
		//echo 'unknow user';
		$error =$err->failRead;
	}
}

?>